﻿using System;

namespace Eirene.Core.Model
{
    /// <summary>
    /// Encapsulates details about the owner of an item.
    /// </summary>
    public class Owner : IEquatable<Owner>
    {
        #region Properties

        /// <summary>
        /// Gets or sets the owner's first name.
        /// </summary>
        public string FirstName { get; set; }

        /// <summary>
        /// Gets or sets the owner's last name.
        /// </summary>
        public string LastName { get; set; }

        /// <summary>
        /// Gets or sets the default owner.
        /// </summary>
        //public bool IsDefault { get; set; }

        protected bool _isDefault;
        public bool IsDefault
        {
            get { return _isDefault; }
            set
            {
                if (_isDefault != value)
                {
                    _isDefault = value;
                    OnIsDefaultChanged();
                }
            }
        }

        #endregion

        public event EventHandler IsDefaultChanged;

        protected virtual void OnIsDefaultChanged()
        {
            if (IsDefaultChanged != null)
                IsDefaultChanged(this, EventArgs.Empty);
        }

        #region Implementation

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>True if the current object is equal to the other parameter - otherwise False.</returns>
        public bool Equals(Owner other)
        {
            //Check whether the compared object is null.
            if (Object.ReferenceEquals(other, null)) return false;

            //Check whether the compared object references the same data.
            if (Object.ReferenceEquals(this, other)) return true;

            //Check whether the products' properties are equal.
            return LastName.Equals(other.LastName) && FirstName.Equals(other.FirstName);
        }

        #endregion

        #region Overrides

        /// <summary>
        /// If Equals() returns true for a pair of objects then
        /// GetHashCode() must return the same value for these objects.
        /// </summary>
        public override int GetHashCode()
        {
            //Get hash code for the Name field if it is not null.
            int hashProductFirstName = FirstName == null ? 0 : FirstName.GetHashCode();

            //Get hash code for the Code field.
            int hashProductLastName = LastName.GetHashCode();

            //Calculate the hash code for the product.
            return hashProductFirstName ^ hashProductLastName;
        }

        #endregion
    }
}
